const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    id:'',
    detail:'',
  },
  onLoad(option) {
    if(option.id){
      this.setData({
        id:option.id,
      })
    }
  },
  onShow(){
    if(this.data.id){
      this.detailForUser()
    }
  },
  detailForUser(){
    var data={
      caseInfoId:this.data.id
    }
    Controller.detailForUser(data).then(res=>{
      if(res.data.baseData){
        if(res.data.baseData.otherImgUrls){
          res.data.baseData.otherImgUrls=res.data.baseData.otherImgUrls.split(',');
        }
        this.setData({
          detail:res.data.baseData,
        })
      }
      
    }).catch(res=>{

    })
  },
  cancel(){
    var that=this;
    wx.showModal({
        title: '',
        content: "确定撤销该案源吗？",
        confirmColor:'#0557A8',
        cancelColor:'#C2C2C2',
        success (res) {
          if (res.confirm) {
            that.cancelCase()
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
  },
  cancelCase(){
    Controller.cancelCase({caseInfoId:this.data.id}).then(res=>{
      // this.detailForUser();
      wx.navigateBack({ //返回
        delta: 1
      })
    }).catch(res=>{

    })
  },
  look(){
    wx.showModal({
        title: '不通过原因',
        content: this.data.detail.approveReason,
        confirmColor:'#0557A8',
        showCancel:false,
        cancelColor:'#C2C2C2',
        success (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
  },
  complete(){
    var that=this;
    wx.showModal({
        title: '',
        content: "确定服务已完成吗？",
        confirmColor:'#0557A8',
        cancelColor:'#C2C2C2',
        success (res) {
          if (res.confirm) {
            that.finishCase()
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
  },
  finishCase(){
    Controller.finishCase({caseInfoId:this.data.id}).then(res=>{
      this.detailForUser();
    }).catch(res=>{

    })
  },
  golink(e){
    var url=e.currentTarget.dataset.url;
    if (!wx.getStorageSync('logintoken')) {
      app.goLogin(false)
      return
    }
    wx.navigateTo({
      url:e.currentTarget.dataset.url
    });
  },
  preview(event) {
    let currentUrl = event.currentTarget.dataset.src
    wx.previewImage({
      current: currentUrl, // 当前显示图片的http链接
      urls: this.data.detail.otherImgUrls // 需要预览的图片http链接列表
    })
  },
  onShareAppMessage: function (e) {
    
  },
  onShareTimeline: function(res){
    
  },

})